// JavaScript Document
var user_info = {
	qiye: function () {
		var data = {};
		$.commonAjax({
			url: 'B046',
			type: 'GET',
			data: data,
			isShowError: true,
			success: function (res) {

			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, user_info: function () {
		var data = {};
		$.commonAjax({
			url: 'B039',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				var obj = $('.list-info').parent();
				if (res.data.member.telephone) {
					$(obj[1]).children('div[class="list-info"]').text(res.data.member.telephone);
					$(obj[1]).children('div[class="list-operation"]').text('已认证').attr('disabled', true);
				}
				if (res.data.member.email) {
					$(obj[0]).children('div[class="list-info"]').text(res.data.member.email);
					$(obj[0]).children('div[class="list-operation"]').text('已绑定').attr('disabled', true);
				}
				if (res.data.personal.status) {
					$(obj[2]).children('div[class="list-info"]').text(res.data.personal.realName);
					$(obj[2]).children('div[class="list-operation"]').text('已认证').attr('disabled', true);
				}
				if (res.data.enterprise.status) {
					$(obj[3]).children('div[class="list-info"]').text(res.data.enterprise.enterpriseName);
					$(obj[3]).children('div[class="list-operation"]').text('已认证').attr('disabled', true);
				}
				if (res.data.vip) {
					var show = '';
					if (res.data.vip == 1) {
						show = '用户VIP';
					} else if (res.data.vip == 9) {
						show = '集团VIP';
					}
					$(obj[4]).children('div[class="list-info"]').text(show);
					$(obj[4]).children('div[class="list-operation"]').text('已认证').attr('disabled', true);
				}
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	},
	geren: function () {
		var data = {};
		$.commonAjax({
			url: 'B045',
			type: 'GET',
			data: data,
			isShowError: true,
			success: function (res) {
				//.text(res.data.realName);
				/*if(res.data.status){
					var obj = $('.list-info').parent();
					$(obj[2]).children('div[class="list-info"]').text(res.data.realName);
					$(obj[2]).children('div[class="list-operation"]').text('已认证');
				}*/
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	},
	bind_email: function (email, mcode) {
		var data = { email: email, mcode: mcode };
		$.commonAjax({
			url: 'B041',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				$.alert(res.msg);
				if (res.code == 200) {
					setTimeout(function () { window.location.href = '' }, 1500);
				}
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, get_email_code: function (email) {
		var data = { email: email, type: 4 };
		$.commonAjax({
			url: 'B040',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				$.alert(res.msg);
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, change_pwd: function (data) {

		$.commonAjax({
			url: 'B055',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				$.layermsg(res.msg);
				if (res.code = 200)
					$('.pswMask').hide();
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, follow_list: function () {
		var data = {};
		$.commonAjax({
			url: 'B095',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				console.log(res.data)
				var htm = '';
				$.each(res.data, function (k, v) {
					htm += '<li val="' + v.id + '" isFollow="' + v.isFollow + '" onclick="user_info.follow_check(this)" class="shop-list ' + (v.isFollow ? 'shop-list-active' : '') + '"><span class="chooseIcon"></span>' + v.name + '</li>';
				});
				$('.interest-con').html(htm);
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, follow_add: function (data) {
		$.commonAjax({
			url: 'B093',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				user_info.follow_list();
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, follow_delete: function (data) {
		$.commonAjax({
			url: 'B094',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				user_info.follow_list();
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, follow_check: function (obj) {
		var data = { categoryCode: $(obj).attr('val') };
		var isFollow = $(obj).attr('isFollow');
		if (isFollow == 'true')
			user_info.follow_delete(data);
		else
			user_info.follow_add(data);

	}, follow_auction: function () {
		var data = {};
		$.commonAjax({
			url: 'B096',
			type: 'POST',
			//async: false,
			data: data,
			isShowError: true,
			success: function (res) {
				//console.log(res);
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}
}
$(function () {
	user_info.follow_auction();
	user_info.follow_list();
	user_info.qiye();
	user_info.user_info();
	user_info.geren();
	$('.list-operation').click(function () {
		var idx = $(this).parent().index();
		if ($(this).attr('disabled') == 'disabled')
			return false;
		switch (idx) {
			case 0:
				$('.emailMask').show();
				$('.emailMask').find('input:last').click(function () {
					var email = $('.emailMask').find('input:first').val();
					var mcode = $('.emailMask').find('input:eq(1)').val();
					user_info.bind_email(email, mcode);
				});
				$('.emailMask').find('div:first').click(function () {
					$('.emailMask').hide();
				});
				$('.emailMask').find('div[class="getCode"]').click(function () {
					var email = $('.emailMask').find('input:first').val();
					user_info.get_email_code(email)
				})
				break;
			case 4:
				$('.vipMask').show();
				$('.vipMask').find('div:first').click(function () {
					$('.vipMask').hide();
				});
				break;
			case 2:
				bp.jump('shimingrz');
				break;
			case 5:
				$('.pswMask').show();
				$('.pswMask').find('div:first').click(function () {
					$('.pswMask').hide();
				});
				$('.pswMask').find('input:last').click(function () {
					var data = {}
					data.oldpassword = $('.pswMask').find('input:first').val();
					data.password = $('.pswMask').find('input:eq(1)').val();
					data.repassword = $('.pswMask').find('input:eq(2)').val();
					user_info.change_pwd(data);
				});
				break;
		}
	});
})